package
{ 
	import flash.events.MouseEvent;
	import mx.controls.CheckBox;
	import mx.core.Application;
	
	public class CheckBoxHeaderRenderer extends CheckBox{
		private var _data:CheckBoxHeaderColumn;
		
		public function CheckBoxHeaderRenderer(){
		    super();
		    NotifyCheckboxEvent.dispatcher.addEventListener(NotifyCheckboxEvent.UPDATECHECKBOX_HEADER, updateHeader);
		}
		
		override public function get data():Object{
		   	return _data;
		}
		
		override public function set data(value:Object):void{
		  	_data = value as CheckBoxHeaderColumn;
		   	selected = _data.selected;
		}
		
		override protected function clickHandler(event:MouseEvent):void{
		   	super.clickHandler(event);
		   	data.selected = selected;
		   	data.dispatchEvent(event);
		   	var app:Application = this.parentApplication as Application;
		   	app['selecteds'].splice(0,app['selecteds'].length);
		   	if(selected){
		   		for each(var item:XML in app['dg'].dataProvider){
		   			app['selecteds'].push(item.@rowId);
		   		}
		   	}
		}
		
		public function updateHeader(evt:NotifyCheckboxEvent):void{
			selected = evt.data.selected;
			data.selected = evt.data.selected;
		}
	}
}